﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Maticsoft.Common;

namespace Maticsoft.Web.Admin.Shopping
{
    public partial class EditDelivery : PageBase
    {
        BLL.DeliveryWay bll = new BLL.DeliveryWay();
        Model.DeliveryWay model = null;

        string id = string.Empty;
        protected void Page_Load(object sender, EventArgs e)
        {
            Check("shopping", "modify");

            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                id = Request.QueryString["id"];

                if (!IsPostBack)
                {
                    GetData();
                }
            }
        }

        protected void GetData()
        {
            if (!string.IsNullOrEmpty(id))
            {
                model = bll.GetModel(int.Parse(id));
                txtTitle.Text = model.DeliveryName;
                txtPrice.Text = model.Price;
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            if (!string.IsNullOrEmpty(id))
            {
                model = bll.GetModel(int.Parse(id));
                model.DeliveryName = txtTitle.Text.Trim();
                model.Price = txtPrice.Text.Trim();
                model.UpdateTime = DateTime.Now;
                model.Detail = "运费" + model.Price;
                model.IsActive = 1;
                bll.Update(model);
                MessageBox.ShowAndRedirect(this.Page, "修改成功", "Delivery.aspx");
            }
            else
            {
                model = new Model.DeliveryWay();
                model.DeliveryId = bll.GetMaxId();
                model.DeliveryName = txtTitle.Text.Trim();
                model.Price = txtPrice.Text.Trim();
                model.Detail = "运费" + model.Price;
                model.UpdateTime = DateTime.Now;
                model.IsActive = 1;
                bll.Add(model);
                MessageBox.ShowAndRedirect(this.Page, "添加成功", "Delivery.aspx");
            }
        }
    }
}